package com.kfm.pm.reader;

import java.io.*;
import java.nio.charset.Charset;

public class FileReaderDemo {

    public static void main(String[] args) {
        // 用默认的字符集获取一个字符输入流 UTF-8
        try (FileReader reader = new FileReader(new File("E:\\KFM\\test\\hello.txt"));
             FileReader reader1 = new FileReader(new File("E:\\KFM\\test\\hello.txt"), Charset.forName("GBK"))
        ) {
            int c = reader1.read();
            System.out.println((char) c);
            char[] chars = new char[20];
//            int read = reader1.read(chars); // 将字符读到chars中，返回实际读取的字符数
//            System.out.println(new String(chars, 0, read));
            int read = reader1.read(chars, 2, 10);
            System.out.println(new String(chars, 2, read));
            System.out.println(reader1.markSupported()); // 是否支持mark() 方法
            System.out.println(reader.getEncoding());
            System.out.println(reader1.getEncoding());
//            reader1.mark(1);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
